<template>
  <div class="app-container">

    <Tabs :active-value="queryParams.tabType" :tabs="tabs" @change="changeTab"></Tabs>

    <SearchContent :queryParams="queryParams" @query="handleQuery" @reset="resetQuery" :key="queryParams.tabType">

      <el-col :span="6">
        <el-form-item label="客户名称:" prop="customerName">
          <el-input v-model="queryParams.customerName" clearable placeholder="请输入客户名称"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="业务类型:" prop="businessType">
          <el-select v-model="queryParams.businessType" clearable>
            <el-option v-for="dict in dict.type.business_type" :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="客户类型:" prop="customerType">
          <el-select v-model="queryParams.customerType" clearable>
            <el-option v-for="dict in dict.type.customer_type" :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="租赁用途:" prop="leasePurpose">
          <el-select v-model="queryParams.leasePurpose" clearable>
            <el-option v-for="dict in dict.type.rental_purpose" :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="客户标签:" prop="customerSource">
          <el-select v-model="queryParams.customerSource" clearable>
            <el-option v-for="dict in dict.type.customer_label" :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="客户等级:" prop="customerLevel">
          <el-select v-model="queryParams.customerLevel" clearable>
            <el-option v-for="dict in dict.type.customer_level" :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="客户属性:" prop="clientProperty">
          <el-select v-model="queryParams.clientProperty" clearable>
            <el-option v-for="dict in dict.type.customer_property" :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="是否老客户:" prop="areYouALoyalCustomer">
          <el-select v-model="queryParams.areYouALoyalCustomer" clearable>
            <el-option v-for="dict in dict.type.business_yes_no" :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="线索来源:" prop="clueClassification">
          <el-select v-model="queryParams.clueClassification" placeholder="请选择线索来源" clearable>
            <el-option v-for="dict in dict.type.clues_source" :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="额度申请编号:" prop="orderNo">
          <el-input v-model="queryParams.orderNo" clearable placeholder="请输入额度申请编号"></el-input>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="车辆信息:" prop="carInfo">
          <el-input v-model="queryParams.carInfo" clearable placeholder="请输入车辆厂商/车型/款型"></el-input>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="提交人:" prop="submitter">
          <el-input v-model="queryParams.submitter" clearable placeholder="请输入提交人"></el-input>
        </el-form-item>
      </el-col>

      <el-col :span="6" v-if="queryParams.tabType<2">
        <el-form-item label="是否补充资料:" prop="supplemented" label-width="130px">
          <el-select v-model="queryParams.supplemented" clearable>
            <el-option v-for="dict in dict.type.business_yes_no" :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="提交时间:">
          <el-date-picker v-model="submitTimes" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" format="yyyy-MM-dd"
                          @change="changeSubmitTime"></el-date-picker>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="审核人:" prop="auditPerson">
          <el-input v-model="queryParams.auditPerson" clearable placeholder="请输入审核人"></el-input>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="信审申请编号:" prop="applicationNo">
          <el-input v-model="queryParams.applicationNo" clearable placeholder="请输入信审申请编号"></el-input>
        </el-form-item>
      </el-col>

      <el-col :span="6" v-if="queryParams.tabType!=1&&queryParams.tabType!=5">
        <el-form-item label="审核时间:">
          <el-date-picker v-model="auditTimes" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" format="yyyy-MM-dd"
                          @change="changeAuditTime"></el-date-picker>
        </el-form-item>
      </el-col>

      <el-col :span="6" v-if="queryParams.tabType<3">
        <el-form-item label="信审状态:" prop="creditReviewStatus">
          <el-select v-model="queryParams.creditReviewStatus" clearable>
            <el-option v-for="dict in dict.type.credit_review_status" :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6" v-if="queryParams.tabType==1&&queryParams.tabType==5">
        <el-form-item label="受理时间:">
          <el-date-picker v-model="handlingTimes" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" format="yyyy-MM-dd"
                          @change="changeHandlingTime"></el-date-picker>
        </el-form-item>
      </el-col>

      <el-col :span="6" v-if="queryParams.tabType==5">
        <el-form-item label="撤单时间:">
          <el-date-picker v-model="invalidTimes" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" format="yyyy-MM-dd"
                          @change="changeInvalidTime"></el-date-picker>
        </el-form-item>
      </el-col>

    </SearchContent>

    <div class="card-wrap paddingAll20">
      <div class="flex-row">
        <template v-if="queryParams.tabType == 0">
          <div class="statisticsInfo">
            <span>信审申请总数</span>
            <span class="countInfo">{{ statisticsInfo.applicationsTotal || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>信审中总数</span>
            <span class="countInfo">{{ statisticsInfo.inProgressTotal || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>全部通过总数</span>
            <span class="countInfo">{{ statisticsInfo.allPassTotal || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>部分通过总数</span>
            <span class="countInfo">{{ statisticsInfo.partlyPassTotal || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>拒绝总数</span>
            <span class="countInfo">{{ statisticsInfo.rejectionTotal || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>不予准入总数</span>
            <span class="countInfo">{{ statisticsInfo.notAdmittedTotal || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>撤单总数</span>
            <span class="countInfo">{{ statisticsInfo.cancelTotal || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>申请总台数</span>
            <span class="countInfo">{{ statisticsInfo.applicationsTotalOfUnits || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>申请总金额</span>
            <span class="countInfo">{{ format_thousand(statisticsInfo.applicationsTotalOfAmount) || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>信审中总台数</span>
            <span class="countInfo">{{ statisticsInfo.inProgressTotalOfUnits || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>通过总台数</span>
            <span class="countInfo">{{ statisticsInfo.passTotalOfUnits || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>拒绝总台数</span>
            <span class="countInfo">{{ statisticsInfo.rejectionTotalOfUnits || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>不予准入总台数</span>
            <span class="countInfo">{{ statisticsInfo.notAdmittedTotalOfUnits || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>撤单总台数</span>
            <span class="countInfo">{{ statisticsInfo.cancelTotalOfUnits || 0 }}</span>
          </div>
        </template>
        <template v-else-if="queryParams.tabType == 1">
          <div class="statisticsInfo">
            <span>信审中总数</span>
            <span class="countInfo">{{ statisticsInfo.inProgressTotal || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>待受理</span>
            <span class="countInfo">{{ statisticsInfo.pendingAcceptance || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>待准入</span>
            <span class="countInfo">{{ statisticsInfo.pendingAdmission || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>待提交批复建议</span>
            <span class="countInfo">{{ statisticsInfo.pendingApproval || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>批复建议审批中</span>
            <span class="countInfo">{{ statisticsInfo.inApproval || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>批复建议被拒绝</span>
            <span class="countInfo">{{ statisticsInfo.approvalRejection || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>批复建议通过</span>
            <span class="countInfo">{{ statisticsInfo.approvalPass || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>信审中总台数</span>
            <span class="countInfo">{{ statisticsInfo.inProgressTotalOfUnits || 0 }}</span>
          </div>

        </template>
        <template v-else-if="queryParams.tabType == 2">
          <div class="statisticsInfo">
            <span>信审通过总数</span>
            <span class="countInfo">{{ statisticsInfo.passTotal || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>全部通过总数</span>
            <span class="countInfo">{{ statisticsInfo.allPassTotal || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>部分通过总数</span>
            <span class="countInfo">{{ statisticsInfo.partlyPassTotal || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>通过总台数</span>
            <span class="countInfo">{{ statisticsInfo.passTotalOfUnits || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>拒绝总台数</span>
            <span class="countInfo">{{ statisticsInfo.rejectionTotalOfUnits || 0 }}</span>
          </div>

        </template>
        <template v-else-if="queryParams.tabType == 3">
          <div class="statisticsInfo">
            <span>拒绝总数</span>
            <span class="countInfo">{{ statisticsInfo.rejectionTotal || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>拒绝总台数</span>
            <span class="countInfo">{{ statisticsInfo.rejectionTotalOfUnits || 0 }}</span>
          </div>

        </template>
        <template v-else-if="queryParams.tabType == 4">
          <div class="statisticsInfo">
            <span>不予准入总数</span>
            <span class="countInfo">{{ statisticsInfo.notAdmittedTotal || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>不予准入总台数</span>
            <span class="countInfo">{{ statisticsInfo.notAdmittedTotalOfUnits || 0 }}</span>
          </div>

        </template>
        <template v-else-if="queryParams.tabType == 5">
          <div class="statisticsInfo">
            <span>撤单总数</span>
            <span class="countInfo">{{ statisticsInfo.cancelTotal || 0 }}</span>
          </div>
          <div class="statisticsInfo">
            <span>撤单总台数</span>
            <span class="countInfo">{{ statisticsInfo.cancelTotalOfUnits || 0 }}</span>
          </div>

        </template>
      </div>
    </div>

    <div class="card-wrap paddingAll20">
      <div class="table-title-wrap flex-row-end">
        <div style="width: auto">
          <el-button type="primary" size="mini" @click="handleExport"
                     v-hasPermi="['letterReview:letterReview:export']">导出
          </el-button>
          <el-button v-hasPermi="['letterReview:letterReview:acceptance']" type="success" size="mini" @click="batchAcceptance">批量受理
          </el-button>
        </div>

      </div>

      <el-table
          v-loading="loading"
          :data="dataList"
          :span-method="arraySpanMethod"
          @selection-change="selectionLineChangeHandle"
          :header-cell-style="{ background: '#FAFAFA', color: '#000000' }" border>
        <el-table-column
            prop="selection"
            type="selection"
            :selectable="checkSelectable"
            width="55"
        />
        <el-table-column prop="operation" label="操作" align="center" width="200px" class-name="small-padding fixed-width" fixed="left">
          <template slot-scope="{row}">

            <template v-if="row.creditReviewStatus ==1">
              <e-button v-hasPermi="['letterReview:letterReview:acceptance']" size="mini" type="text" @click="handleOperate(1,row)"
              >受理
              </e-button>
              <e-button v-hasPermi="['letterReview:letterReview:conversion']" size="mini" type="text" @click="handleOperate(3,row)"
              >改派
              </e-button>
              <e-button v-hasPermi="['letterReview:letterReview:detail']" size="mini" type="text" @click="handleOperate(2,row)"
              >信审详情
              </e-button>
            </template>

            <template v-else-if="row.creditReviewStatus ==2 && row.isRecipient">
              <e-button v-hasPermi="['letterReview:letterReview:access']" size="mini" type="text" @click="handleOperate(4,row)"
              >准入/不予准入
              </e-button>
              <e-button v-hasPermi="['letterReview:letterReview:conversion']" size="mini" type="text" @click="handleOperate(3,row)"
              >改派
              </e-button>
              <e-button v-hasPermi="['letterReview:letterReview:additional']" size="mini" type="text" @click="handleOperate(10,row)"
              >补充资料
              </e-button>
            </template>

            <template v-else-if="row.creditReviewStatus ==3">
              <!-- 只有领导可以改派 暂未处理没有判断依据-->
              <e-button v-hasPermi="['letterReview:letterReview:conversion']" size="mini" type="text" @click="handleOperate(3,row)"
              >改派
              </e-button>
              <template v-if="row.isRecipient">
                <e-button v-hasPermi="['letterReview:letterReview:commitSuggestion']" size="mini" type="text" @click="handleOperate(5,row)"
                >提交批复建议
                </e-button>
                <e-button v-hasPermi="['letterReview:letterReview:additional']" size="mini" type="text" @click="handleOperate(10,row)"
                >补充资料
                </e-button>
              </template>
            </template>

            <template v-else-if="row.creditReviewStatus ==4">
              <e-button v-hasPermi="['letterReview:letterReview:conversion']" size="mini" type="text" @click="handleOperate(3,row)"
              >改派
              </e-button>
              <e-button v-hasPermi="['letterReview:letterReview:detail']" size="mini" type="text" @click="handleOperate(2,row)"
              >信审详情
              </e-button>
              <e-button v-hasPermi="['letterReview:letterReview:suggestionDetail']" size="mini" type="text" @click="handleOperate(9,row)"
              >批复建议详情
              </e-button>

              <e-button v-hasPermi="['letterReview:letterReview:additional']" v-if="row.isRecipient" size="mini" type="text" @click="handleOperate(10,row)"
              >补充资料
              </e-button>
            </template>

            <template v-else-if="row.creditReviewStatus ==5">
              <e-button v-hasPermi="['letterReview:letterReview:conversion']" size="mini" type="text" @click="handleOperate(3,row)"
              >改派
              </e-button>
              <template v-if="row.isRecipient">
                <e-button v-hasPermi="['letterReview:letterReview:commitSuggestion']" v-if="row.isRecipient" size="mini" type="text" @click="handleOperate(5,row)"
                >提交批复建议
                </e-button>
                <e-button v-hasPermi="['letterReview:letterReview:additional']" v-if="row.isRecipient" size="mini" type="text" @click="handleOperate(10,row)"
                >补充资料
                </e-button>
              </template>
              <e-button v-hasPermi="['letterReview:letterReview:suggestionDetail']" size="mini" type="text" @click="handleOperate(9,row)"
              >批复建议详情
              </e-button>

            </template>

            <template v-else-if="row.creditReviewStatus ==6">
              <e-button v-hasPermi="['letterReview:letterReview:conversion']" size="mini" type="text" @click="handleOperate(3,row)"
              >改派
              </e-button>
              <template v-if="row.isRecipient">
                <e-button v-hasPermi="['letterReview:letterReview:commitResult']" size="mini" type="text" @click="handleOperate(6,row)"
                >全部通过
                </e-button>
                <e-button v-hasPermi="['letterReview:letterReview:commitResult']" size="mini" type="text" @click="handleOperate(7,row)"
                >部分通过
                </e-button>
                <e-button v-hasPermi="['letterReview:letterReview:commitResult']" size="mini" type="text" @click="handleOperate(8,row)"
                >拒绝
                </e-button>
                <e-button v-hasPermi="['letterReview:letterReview:additional']" size="mini" type="text" @click="handleOperate(10,row)"
                >补充资料
                </e-button>
              </template>
              <e-button v-hasPermi="['letterReview:letterReview:suggestionDetail']" size="mini" type="text" @click="handleOperate(9,row)"
              >批复建议详情
              </e-button>

            </template>

            <template v-else-if="row.creditReviewStatus ==7||row.creditReviewStatus ==8">
              <e-button v-hasPermi="['letterReview:letterReview:detail']" size="mini" type="text" @click="handleOperate(11,row)"
              >查看
              </e-button>
              <e-button v-hasPermi="['letterReview:letterReview:voidRemindCredit']" v-if="row.displayVoid" size="mini" type="text" @click="handleOperate(12,row)"
              >作废剩余额度
              </e-button>
            </template>

            <template v-else>
              <e-button v-hasPermi="['letterReview:letterReview:detail']" size="mini" type="text" @click="handleOperate(11,row)"
              >查看
              </e-button>
            </template>

          </template>
        </el-table-column>

        <!-- 普通列插槽 -->
        <el-table-column label="信审状态" align="center" prop="ruleName" min-width="120px" show-overflow-tooltip fixed="left">
          <template v-slot="{row}">
            <dict-tag :options="dict.type.credit_review_status" :value="row.creditReviewStatus"/>
            <el-tag v-if="row.supplemented==1" type="warning">待补充资料</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="序号" type="index" align="center" prop="sortIndex" min-width="120px" show-overflow-tooltip fixed="left"/>
        <el-table-column label="信审申请编号" align="center" prop="applicationNo" min-width="180px" show-overflow-tooltip fixed="left">
          <template v-slot="{row}">
            <e-button class="enable-text-select" v-hasPermi="['letterReview:letterReview:detail']" size="mini" type="text" @click="handleOperate(11,row)"
            >
              {{ row.applicationNo }}
            </e-button>
          </template>
        </el-table-column>
        <el-table-column label="客户名称" align="center" prop="customerName" min-width="120px" show-overflow-tooltip fixed="left"/>
        <el-table-column label="业务类型" align="center" prop="businessType" min-width="120px" show-overflow-tooltip>
          <template v-slot="{row}">
            <dict-tag :options="dict.type.business_type" :value="row.businessType"/>
          </template>
        </el-table-column>
        <el-table-column label="产品方案" align="center" prop="planName" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="申请类型" align="center" prop="applicationType" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="车牌号" align="center" prop="carNo" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="车辆类型" align="center" prop="vehicleModel" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="车辆款型" align="center" prop="vehicleStyle" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="新车采购单价" align="center" prop="purchasePrice" min-width="120px" show-overflow-tooltip>
          <template v-slot="{row}">
            {{format_thousand(row.purchasePrice)}}
          </template>
        </el-table-column>
        <el-table-column label="旧车当前估值" align="center" prop="currentValuation" min-width="120px" show-overflow-tooltip>
          <template v-slot="{row}">
            {{format_thousand(row.currentValuation)}}
          </template>
        </el-table-column>
        <el-table-column label="新车采购总额" align="center" prop="newCarProcurementAmount" min-width="120px" show-overflow-tooltip>
          <template v-slot="{row}">
            {{format_thousand(row.newCarProcurementAmount)}}
          </template>
        </el-table-column>
        <el-table-column label="旧车当前估值总额" align="center" prop="oldCarValuationAmount" min-width="140px" show-overflow-tooltip>
          <template v-slot="{row}">
            {{format_thousand(row.oldCarValuationAmount)}}
          </template>
        </el-table-column>
        <el-table-column label="租赁用途" align="center" prop="leasePurpose" min-width="120px" show-overflow-tooltip>
          <template v-slot="{row}">
            <dict-tag :options="dict.type.rental_purpose" :value="row.leasePurpose"/>
          </template>
        </el-table-column>
        <el-table-column label="租赁期限" align="center" prop="leaseTerm" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="保证金" align="center" prop="margin" min-width="120px" show-overflow-tooltip>
          <template v-slot="{row}">
            {{format_thousand(row.margin)}}
          </template>
        </el-table-column>
        <el-table-column label="每期租金" align="center" prop="monthlyRent" min-width="120px" show-overflow-tooltip>
          <template v-slot="{row}">
            {{format_thousand(row.monthlyRent)}}
          </template>
        </el-table-column>
        <el-table-column label="首期租金、比例" align="center" prop="firstInstallmentRentalRatio" min-width="150px" show-overflow-tooltip>
          <template v-slot="{row}">
            <template v-if="row.firstInstallmentRentalRatio">
              {{ row.firstInstallmentRent }} 、{{ row.firstInstallmentRentalRatio }}%
            </template>
            <template v-else>
              -- 、--
            </template>
          </template>
        </el-table-column>
        <el-table-column label="残值、比例" align="center" prop="residualValueRatio" min-width="120px" show-overflow-tooltip>
          <template v-slot="{row}">
            <template v-if="row.residualValueRatio">
              {{ row.residualValue }} 、 {{ row.residualValueRatio }}%
            </template>
            <template v-else>
              -- 、--
            </template>
          </template>
        </el-table-column>
        <el-table-column label="租金支付方式" align="center" prop="rentPaymentMethod" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="申请总台数" align="center" prop="totalApplicationNumber" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="信审中总台数" align="center" prop="totalCringNumber" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="通过总台数" align="center" prop="totalPassNumber" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="拒绝总台数" align="center" prop="totalRejectNumber" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="不予准入总台数" align="center" prop="totalNotAdmittedNumber" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="撤单总台数" align="center" prop="totalCancelNumber" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="申请台数" align="center" prop="numberOfApplications" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="通过台数" align="center" prop="numberOfUnitsPassed" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="拒绝台数" align="center" prop="rejectedUnits" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="已使用台数" align="center" prop="numberOfUnitsUsed" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="作废台数" align="center" prop="numberOfInvalidUnits" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="冻结台数" align="center" prop="numberOfFrozenUnits" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="剩余可使用台数" align="center" prop="numberOfRemainingUnits" min-width="120px" show-overflow-tooltip>
          <template v-slot="{row}">
            <span>{{ row.numberOfUnitsPassed - row.numberOfUnitsUsed - row.numberOfInvalidUnits - row.numberOfFrozenUnits }}</span>
          </template>
        </el-table-column>
        <el-table-column label="通过台数状态" align="center" prop="effectiveStatus" min-width="120px" show-overflow-tooltip>
          <template v-slot="{row}">
            <span>{{ row.effectiveStatus|effectiveStatus }}</span>
          </template>
        </el-table-column>
        <el-table-column label="通过台数到期时间" align="center" prop="creditReviewDeadline" min-width="140px" show-overflow-tooltip/>
        <el-table-column label="客户编号" align="center" prop="customerCode" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="客户类型" align="center" prop="customerType" min-width="120px" show-overflow-tooltip>
          <template v-slot="{row}">
            <dict-tag :options="dict.type.customer_type" :value="row.customerType"/>
          </template>
        </el-table-column>
        <el-table-column label="客户标签" align="center" prop="customerSource" min-width="120px" show-overflow-tooltip>
          <template v-slot="{row}">
            <dict-tag :options="dict.type.customer_label" :value="row.customerSource"/>
          </template>
        </el-table-column>
        <el-table-column label="客户等级" align="center" prop="customerLevel" min-width="100px" show-overflow-tooltip>
          <template v-slot="{row}">
            <dict-tag :options="dict.type.customer_level" :value="row.customerLevel"/>
          </template>
        </el-table-column>
        <el-table-column label="客户属性" align="center" prop="clientProperty" min-width="120px" show-overflow-tooltip>
          <template v-slot="{row}">
            <dict-tag :options="dict.type.customer_property" :value="row.clientProperty"/>
          </template>
        </el-table-column>
        <el-table-column label="是否是老客户" align="center" prop="areYouALoyalCustomer" min-width="120px" show-overflow-tooltip>
          <template v-slot="{row}">
            <dict-tag :options="dict.type.business_yes_no" :value="row.areYouALoyalCustomer"/>
          </template>
        </el-table-column>
        <el-table-column label="线索来源" align="center" prop="clueClassification" min-width="120px" show-overflow-tooltip>
          <template v-slot="{row}">
            <dict-tag :options="dict.type.clues_source" :value="row.clueClassification"/>
          </template>
        </el-table-column>
        <el-table-column label="车辆厂商" align="center" prop="vehicleManufacturers" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="车辆能源类型" align="center" prop="vehicleEnergyType" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="登记性质" align="center" prop="registrationNature" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="里程限制(公里)" align="center" prop="mileageLimit" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="上牌城市" align="center" prop="registeredCity" min-width="120px" show-overflow-tooltip/>

        <el-table-column label="额度申请编号" align="center" prop="orderNo" min-width="180px" show-overflow-tooltip>
          <template v-slot="{row}">
            <e-button class="enable-text-select" size="mini" type="text" @click="goQurtaApplyDetail(row)">
              {{ row.orderNo }}
            </e-button>
          </template>
        </el-table-column>
        <el-table-column label="提交人" align="center" prop="submitter" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="提交时间" align="center" prop="submitTime" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="受理时间" align="center" prop="handlingTime" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="审核时间" align="center" prop="auditTime" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="撤单时间" align="center" prop="invalidTime" min-width="120px" show-overflow-tooltip/>
        <el-table-column label="审核人" align="center" prop="auditPerson" min-width="120px" show-overflow-tooltip/>
      </el-table>
      <pagination :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                  @pagination="getList"/>

    </div>

    <!--改派人员-->
    <el-dialog
        title="改派人员"
        :visible.sync="dialogVisible1"
        width="30%">
      <div>
        <el-form ref="dialogForm" label-width="120px" :model="dialogForm" :rules="rules">
          <el-form-item label="选择改派人员:" prop="auditPerson">
            <el-select v-model="dialogForm.auditId" filterable placeholder="请选择改派人员" style="width: 70%" @change="changePerson">
              <el-option
                  v-for="item in auditPersonList"
                  :key="item.userId"
                  :label="item.userName"
                  :value="item.userId">
              </el-option>
            </el-select>
          </el-form-item>

        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible1 = false">取 消</el-button>
        <el-button type="primary" @click="confimReassign">确 定</el-button>
      </span>
    </el-dialog>
    <!--补充资料-->
    <el-dialog
        title="补充资料"
        :visible.sync="dialogVisible2"
        width="30%">
      <div>
        <el-form ref="dialogForm2" label-width="160px" label-position="right" :model="dialogForm" :rules="rules">
          <el-form-item label="补充资料内容:" prop="remark">
            <el-input type="textarea" placeholder="请输入待补充资料" v-model="dialogForm.remark"></el-input>
          </el-form-item>
          <el-form-item label="是否需添加担保人:" prop="needGuarantor">
            <el-radio-group v-model="dialogForm.needGuarantor">
              <el-radio :label="1">需要</el-radio>
              <el-radio :label="2">不需要</el-radio>
              <el-radio :label="3">选择性提供</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible2 = false">取 消</el-button>
        <el-button type="primary" @click="confimAdditionalMaterials">确 定</el-button>
      </span>
    </el-dialog>


    <reply-suggestions-list ref="replySuggestionsList"></reply-suggestions-list>
    <void-remaining-balance ref="voidRemainingBalance"></void-remaining-balance>
  </div>
</template>

<script>
import SearchContent from "@/components/SearchContent/index.vue";
import Tabs from "@/components/Tabs/index.vue"
import StatisticsInfo from "@/views/letterReview/letterReview/components/statisticsInfo.vue";
import ReplySuggestionsList from "@/views/letterReview/letterReview/components/ReplySuggestionsList.vue";
import VoidRemainingBalance from "@/views/letterReview/letterReview/components/VoidRemainingBalance.vue";
import * as letterReviewApi from "@/api/letterReview/letterReview";
import {listUser} from "@/api/system/user";
import * as contractTemplateApi from "@/api/contractTemplate/contractTemplate";
import {effectiveStatus} from "@/utils/filters";
import {getCreditReviewPersonnel} from "@/api/letterReview/letterReview";
import {format_thousand} from "@/utils/utils";

export default {
  name: "LetterReviewList",
  components: {
    SearchContent,
    Tabs,
    StatisticsInfo,
    ReplySuggestionsList,
    VoidRemainingBalance
  },
  dicts: [
    'business_type',
    'customer_type',
    'customer_level',
    'rental_purpose',
    'customer_label',
    'customer_property',
    'business_yes_no',
    'credit_review_status',
    'clues_source',
  ],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tabType: 0,
        customerName: null,
        businessType: null,
        customerType: null,
        leasePurpose: null,
        customerSource: null,
        customerLevel: null,
        clientProperty: null,
        areYouALoyalCustomer: null,
        clueClassification: null,
        orderNo: null,
        submitter: null,
        supplemented: null,
        submitTimeStart: null,
        submitTimeEnd: null,
        auditPerson: null,
        auditTimeStart: null,
        auditTimeEnd: null,
        passStatus: null,
        applicationNo: null,
        creditReviewStatus: null,
        carInfo: null,
        handlingTimeStart: null,
        handlingTimeEnd: null,
        invalidTimeStart: null,
        invalidTimeEnd: null,
        needCreditReview: 2,

      },
      submitTimes: [],
      auditTimes: [],
      handlingTimes: [],
      invalidTimes: [],
      tabs: [
        {
          label: '全部',
          value: 0
        },
        {
          label: '信审中',
          value: 1
        },
        {
          label: '通过',
          value: 2
        },
        {
          label: '拒绝',
          value: 3
        },
        {
          label: '不予准入',
          value: 4
        },
        {
          label: '撤单',
          value: 5
        }
      ],
      total: 0,
      dataList: [],
      dialogVisible1: false,
      dialogVisible2: false,
      auditPersonList: [],
      dialogForm: {
        id: null,
        //改派
        auditId: null,
        auditPerson: null,
        needGuarantor: 1,
        //补充资料
        remark: null
      },
      rules: {
        auditPerson: [
          {required: true, message: '请选择改派人员', trigger: 'change'},
        ],
        needGuarantor: [
          {required: true, message: '请选择是否需添加担保人', trigger: 'change'},
        ],
        remark: [
          {required: true, message: '请输入补充资料内容', trigger: 'change'},
        ]

      },
      currentId: null,
      statisticsInfo: {},
      batchIdList: [],
      //非合并列字段集合
      unMergeArr: [
        'applicationType',
        'carNo',
        'vehicleModel',
        'vehicleStyle',
        'purchasePrice',
        'currentValuation',
        'vehicleManufacturers',
        'leaseTerm',
        'rentPaymentMethod',
        'vehicleEnergyType',
        'registrationNature',
        'mileageLimit',
        'registeredCity',
        'numberOfApplications',
        'numberOfUnitsPassed',
        'rejectedUnits',
        'numberOfUnitsUsed',
        'numberOfInvalidUnits',
        'numberOfFrozenUnits',
        'numberOfRemainingUnits',
        'effectiveStatus',
        'margin',
        'monthlyRent',
        'firstInstallmentRentalRatio',
        'residualValueRatio'
      ]

    };
  },
  mounted() {
    this.getList()
    this.getStatistics()
    this.getUserList()
  },
  activated() {
    this.getList()
    this.getStatistics()
  },
  methods: {
    format_thousand,
    effectiveStatus,
    changePerson(id) {
      const index = this.auditPersonList.findIndex(item => item.userId == id)
      const obj = this.auditPersonList[index];
      this.dialogForm.auditPerson = obj.userName;
    },
    // 补充资料
    confimAdditionalMaterials() {
      this.$refs['dialogForm2'].validate((valid) => {
        if (valid) {
          letterReviewApi.initiateAddFiles(this.dialogForm).then((res) => {
            this.$message.success('补充资料成功')
            this.dialogVisible2 = false
            this.handleQuery()
          })
        }
      })
    },

    // 确认改派
    confimReassign() {
      this.$refs['dialogForm'].validate((valid) => {
        if (valid) {
          letterReviewApi.reassignment(this.dialogForm).then((res) => {
            this.$message.success('改派成功')
            this.dialogVisible1 = false
            this.handleQuery()
          })
        }
      })
    },
    // 受理
    acceptance(row) {
      this.$alert('确认受理信审申请吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        showCancelButton: true,
      }).then(() => {
        // console.log('确定----')
        letterReviewApi.acceptance(row.id).then((res) => {
          this.$message.success('受理成功')
          this.handleQuery();
        })
      }).catch(() => {

      });
    },
    // 获取系统用户
    getUserList() {
      letterReviewApi.getCreditReviewPersonnel().then(res => {
        this.auditPersonList = res.data;
      })
    },
    changeSubmitTime(val) {
      this.queryParams.submitTimeStart = val[0]
      this.queryParams.submitTimeEnd = val[1]
    },
    changeAuditTime(val) {
      this.queryParams.auditTimeStart = val[0]
      this.queryParams.auditTimeEnd = val[1]
    },
    changeHandlingTime(val) {
      this.queryParams.handlingTimeStart = val[0]
      this.queryParams.handlingTimeEnd = val[1]
    },
    changeInvalidTime(val) {
      this.queryParams.handlingTimeStart = val[0]
      this.queryParams.handlingTimeEnd = val[1]
    },
    changeTab(value) {
      this.queryParams.tabType = value;
      this.handleQuery();
    },
    /** 查询测试单表列表 */
    getList() {
      this.loading = true;
      letterReviewApi.creditReviewlistDetails(this.queryParams).then(res => {
        this.dataList = res.rows;
        this.total = res.total;
        this.setRowspans(this.dataList)
      }).finally(() => {
        this.loading = false
      })
    },
    // 信审记录统计
    getStatistics() {
      letterReviewApi.statistics(this.queryParams).then(res => {
        this.statisticsInfo = res.data;
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
      this.getStatistics()
    },

    /** 重置按钮操作 */
    resetQuery() {
      console.log('component', this)
      this.$refs?.queryForm?.resetFields();
      this.submitTimes = []
      this.auditTimes = []
      this.handlingTimes = []
      this.invalidTimes = []
      this.queryParams.submitTimeStart = null;
      this.queryParams.submitTimeEnd = null;
      this.queryParams.auditTimeStart = null;
      this.queryParams.auditTimeEnd = null;
      this.queryParams.handlingTimeStart = null;
      this.queryParams.handlingTimeEnd = null;
      this.queryParams.invalidTimeStart = null;
      this.queryParams.invalidTimeEnd = null;
      this.handleQuery();

    },

    // 相关按钮的点击事件
    handleOperate(type, row) {
      switch (type) {//按钮类型
        case 1://受理
          this.acceptance(row)
          break
        case 2://信审详情
        case 4://准入/不予准入
        case 5://提交批复建议
        case 11://查看
          this._toPage({
            name: 'LetterReviewDetail',
            query: {
              applicationNo: row.applicationNo,
              id: row.id
            }
          })
          break
        case 3://改派
          this.dialogVisible1 = true
          this.$refs?.dialogForm?.resetFields()
          this.dialogForm.id = row.id
          this.dialogForm.auditId = null
          this.dialogForm.auditPerson = null
          break

        case 6://全部通过
          this._toPage({
            name: 'LetterReviewDetail',
            query: {
              applicationNo: row.applicationNo,
              id: row.id,
              approval: 7,
            }
          })
          break
        case 7://部分通过
          this._toPage({
            name: 'LetterReviewDetail',
            query: {
              applicationNo: row.applicationNo,
              id: row.id,
              approval: 8,
            }
          })
          break
        case 8://拒绝
          this._toPage({
            name: 'LetterReviewDetail',
            query: {
              applicationNo: row.applicationNo,
              id: row.id,
              approval: 9,
            }
          })
          break
        case 9://批复建议详情
          this.$refs.replySuggestionsList.show(row.applicationNo)
          break
        case 10://补充资料
          this.dialogVisible2 = true
          this.$nextTick(() => {
            this.$refs.dialogForm2.resetFields()
            this.dialogForm.id = row.id
          })
          break
        case 12://作废剩余额度
          this.$refs.voidRemainingBalance.show(row.applicationNo)
          break
      }
    },
    //查看额度申请详情
    goQurtaApplyDetail(row) {
      if (this.checkPermi(['quota:apply:list:look'])) {
        this._toPage({
          name: 'ApplyDetails',
          query: {
            calcSchemeId: row.calcSchemeId
          }
        })
      } else {
        this.$message.warning('无权限')
      }
    },
    // 拿唯一主键
    getRowKey(item) {
      return item.id
    },
    // 获取当前选中的信审数据
    selectionLineChangeHandle(vals) {
      console.log('vals', vals)
      if (vals?.length > 0) {
        this.batchIdList = vals.map(item => {
          return item.id
        })
      }
    },
    // 判断表格的复选框是否置灰、禁止选择
    checkSelectable(row, index) {
      //审批通过且是启用
      if (row.creditReviewStatus == 1) {
        return true;
      }
      return false
    },
    // 批量受理
    batchAcceptance() {
      if (this.batchIdList.length > 0) {
        let ids = this.batchIdList.join(',');
        this.$alert('确认受理信审申请吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          showCancelButton: true,
        }).then(() => {
          letterReviewApi.acceptance(ids).then((res) => {
            this.$message.success('受理成功')
            this.handleQuery();
          })
        }).catch(() => {

        });
      } else {
        this.$message.warning('请至少选择一项进行受理')
      }

    },
    // 合并相同编号行
    arraySpanMethod({row, column, rowIndex, columnIndex}) {
      if (!this.unMergeArr.includes(column.property)) {
        return {
          rowspan: row.rowspan,
          colspan: row.rowspan > 0 ? 1 : 0
        }
      }
    },
    // 计算每行的rowspan，只有第一个重复的数据行会设置一个非零的rowspan
    setRowspans(list) {
      // 清除旧的rowspan值
      list.forEach(row => {
        row.rowspan = 1;
      });
      // 使用map创建一个新数组，包含每个applicationNo及其出现的次数
      const applicationNoCounts = list.map(item => item.applicationNo)
          .reduce((acc, applicationNo) => {
            acc[applicationNo] = (acc[applicationNo] || 0) + 1;
            return acc;
          }, {});

      // 遍历原数组，设置正确的rowspan
      list.forEach((item, index) => {
        if (index === 0 || item.applicationNo !== list[index - 1].applicationNo) {
          item.rowspan = applicationNoCounts[item.applicationNo];
        } else {
          item.rowspan = 0; // 对于同组的后续元素，rowspan设置为0
        }
      });
    },
    /** 导出操作 */
    handleExport(row) {
      this.download('/creditReview/creditReview/export', this.queryParams, `信审管理_${new Date().getTime()}.xlsx`)
    },

  }
};
</script>

<style lang="scss" scoped>
.el-table__body-wrapper {
  z-index: 2;
}

.statisticsInfo {
  font-size: 14px;
  color: #464646;
  margin: 8px;
  border: 1px solid #cecece;
  border-radius: 4px;
  padding: 8px;

  span {
    white-space: nowrap;
  }

  .countInfo {
    margin-left: 3px;
    color: #1890FF;
  }
}

.container::-webkit-scrollbar {
  display: none
}


</style>
